﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sudoku
{
    public class SquareBox
    {
        public int[] polje_a { get; set; }
        public int[] polje_b { get; set; }
        public int[] polje_c { get; set; }
        public int[] polje_d { get; set; }
        public int[] polje_e { get; set; }
        public int[] polje_f { get; set; }
        public int[] polje_g { get; set; }
        public int[] polje_h { get; set; }
        public int[] polje_i { get; set; }

        public int[][] tabla;
        
        public CompositeBox[] combox = new CompositeBox[9];

        public SquareBox()
        {
            for (int i = 0; i < 9; i++)
                combox[i] = new CompositeBox();
        }
        public bool isEditable()
        {
            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                    if (!combox[i].Boxes[j].Editable)
                        return false;
            return true;
        }
        public bool isValid()
        {
            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                    if (combox[i].Boxes[j].EnteredDigit != combox[i].Boxes[j].OriginalDigit)
                        return false;
            return true;
        }
        public void popuniTablu()
        {
            tabla = new int[9][];
            tabla[0] = polje_a;
            tabla[1] = polje_b;
            tabla[2] = polje_c;
            tabla[3] = polje_d;
            tabla[4] = polje_e;
            tabla[5] = polje_f;
            tabla[6] = polje_g;
            tabla[7] = polje_h;
            tabla[8] = polje_i;

            for(int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_a[i];
                combox[0].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_b[i];
                combox[1].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_c[i];
                combox[2].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_d[i];
                combox[3].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_e[i];
                combox[4].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_f[i];
                combox[5].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_g[i];
                combox[6].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_h[i];
                combox[7].Boxes[i] = tmp;
            }
            for (int i = 0; i < 9; i++)
            {
                AtomicBox tmp = new AtomicBox();
                tmp.OriginalDigit = polje_i[i];
                combox[8].Boxes[i] = tmp;
            }

        }
    }
}
